package com.qianyue.组合模式;

import java.util.ArrayList;
import java.util.List;

/**
 * 菜单
 *
 * @author qian yue
 * @version v1.0.0
 * @since 2025/2/4 13:39
 */
public class Menu extends MenuComponent {
    private List<MenuComponent> menuComponents = new ArrayList<MenuComponent>();

    public Menu(String name, int level) {
        super(name, level);
    }

    @Override
    public void add(MenuComponent menuComponent) {
        menuComponents.add(menuComponent);
    }

    @Override
    public void remove(MenuComponent menuComponent) {
        menuComponents.remove(menuComponent);
    }

    @Override
    public void print() {
        for (int i = 0; i < level; i++) {
            System.out.print("--");
        }
        System.out.println(name);
        for (MenuComponent menuComponent : menuComponents) {
            menuComponent.print();
        }
    }
}
